package com.audaque.springboot.foshanupload.web.rocketmqdemo.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;


@Slf4j
@Service
//会自动创建消费者组和自定义主题对应的retry主题，，但默认不会自动创建自定义主题，可以配置broker开启自动创建主题
//一个主题下有多个消费者组
@RocketMQMessageListener(topic = "convertAndSend-string", consumerGroup = "convertAndSend-string-push-exception")
public class ConvertAndSendStringListenerException implements RocketMQListener<String> {
    @Override
    public void onMessage(String message) {
        try {
            // 处理消息的逻辑
            System.out.println("Received message: " + message);
            // 假设在这里发生了异常，触发重试
            throw new RuntimeException("Failed to process message.");
        } catch (Exception e) {
            // 异常处理逻辑，例如记录日志等
            System.err.println("Error processing message: " + e.getMessage());
            // 抛出异常，让RocketMQ进行重试
            throw e;
        }
    }
}
